package leetcode.D600.T547;

class Solution {
    public int findCircleNum(int[][] isConnected) {
        int n = isConnected.length, nums = 0;
        for(int i=0; i<n; ++i) {
            if(isConnected[i][i] == 1) {
                nums += 1;
                dfs(isConnected, i);
            }
        }
        return nums;
    }
    private void dfs(int[][] isConnected, int i) {
        int n = isConnected.length;
        isConnected[i][i] = 0;
        for(int j=0; j<n; ++j) {
            if(isConnected[i][j] == 1 && isConnected[j][j] == 1) {
                dfs(isConnected, j);
            }
        }
    }
}
